package net.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.jasper.tagplugins.jstl.core.Out;

import net.display.LigneFraisForfait;
import net.kernel.KFichefrais;
import net.kernel.KVisiteur;
import net.ko.framework.Ko;
import net.ko.http.objects.KRequest;
import net.ko.kobject.KObject;

/**
 * Servlet implementation class AFicheFrais
 */
@WebServlet("/AFicheFrais")
public class AFicheFrais extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public AFicheFrais() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		KVisiteur vi = (KVisiteur) request.getSession().getAttribute("user");
		Calendar cal = Calendar.getInstance();
		int month = cal.get(Calendar.MONTH);
		Date date = new Date(cal.getTime().getTime());
		KFichefrais kf = new KFichefrais();
		try {
			kf.loadOne(Ko.kdatabase(), "idVisiteur=" + vi.getId()
					+ " and mois=" + month);
			if (!kf.isLoaded()) {
				kf.setIdVisiteur(Integer.valueOf("" + vi.getId()));
				kf.setMois(month + "");
				kf.setDateModif(date);
				kf.add(Ko.kdatabase());
			}
			int idFicheFrais = Integer.valueOf(kf.getId() + "");
			KRequest.forward("fichefrais.do", request, response, "id="
					+ idFicheFrais);
		} catch (Exception e) {
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}
